//
//  LXImageAndLabView.m
//  LXLessDemo
//
//  Created by LX on 16/2/10.
//  Copyright © 2016年 LX. All rights reserved.
//

#import "LXImageAndLabView.h"
@interface LXImageAndLabView()
@property(strong,nonatomic)UIImage  *iconImage;
@property(strong,nonatomic)NSString  *textString;
@property(strong,nonatomic)UIFont  *textFount;

@end
@implementation LXImageAndLabView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self addMainView];
    }
    return self;
}
-(instancetype)initWithFrame:(CGRect)frame image:(UIImage *)image text:(NSString *)text fount:(int)fount{
    self = [super initWithFrame:frame];
    if (self) {
        self.textString = text;
        self.iconImage = image ? image:nil;
        self.textFount = [UIFont systemFontOfSize:fount];
        [self addMainView];
    }
    return self;
}
-(void)addMainView{
    self.backgroundColor = [UIColor clearColor];
    CGFloat xPoint = 0;
    if (self.iconImage) {
        UIImageView *view = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetHeight(self.bounds), CGRectGetHeight(self.bounds))];
        view.center = CGPointMake(CGRectGetWidth(view.bounds)/2.0, CGRectGetHeight(self.bounds)/2.0);
        [view setImage:self.iconImage];
        [self addSubview:view];
        
        xPoint = 13;
    }

    UILabel *lab = [LXCommonUtils settingLabWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds) - xPoint, CGRectGetHeight(self.bounds)) text:self.textString textColor:[UIColor whiteColor] fount:self.textFount];
    lab.center = CGPointMake(CGRectGetWidth(lab.bounds)/2.0 + xPoint, CGRectGetHeight(self.bounds)/2.0);
    [self addSubview:lab];
    
    CGRect frame = self.frame;
    frame.size.width = CGRectGetMaxX(lab.frame);
    self.frame = frame;
    
    
}
@end
